package microservicedemo.borrowclient.controller;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import microservicedemo.borrowclient.Client.BorrowServiceClient;
import microservicedemo.borrowclient.model.BorrowRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;

@AllArgsConstructor
@RestController
@Slf4j
public class BorrowServiceClientController {

    @Autowired
    private BorrowServiceClient borrowServiceClient;

    @PostMapping("/borrowBook")
    public void borrowBook(@RequestBody BorrowRecord borrowRecord) {
        log.info("in client -----------borrowBook");
        borrowServiceClient.borrowBook(borrowRecord);
    }

    @PostMapping("/returnBook")
    public boolean returnBook(@RequestBody BorrowRecord borrowRecord) {
        log.info("in client ------------returnBook");
        borrowServiceClient.returnBook(borrowRecord);
        return true;
    }

    @GetMapping("/getOverdueBook")
    public List<BorrowRecord> getOverdueBook(){
        log.info("in client ------------getOverdueBook");
        return borrowServiceClient.getOverdueBook();
    }
}
